﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WapCrawlerLib;
using WapCrawlerCore.Classes;

namespace WapCrawler
{
    public partial class frmTestLinq : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLinqSample1_Click(object sender, EventArgs e)
        {
            TestLinq objTestLinq;
            Response.Write("<h1>Linq Sample 1:</h1><br/>");
            LinqSample objLinqSample = new LinqSample();
            int id = 1;
            string name = "Test " + id.ToString();
            int value = id++;
            objTestLinq = objLinqSample.Test1(name,value);
            Response.Write(string.Format("<h2>Test1: id:{0} - name:{1} - value:{2} </h2><br/>", objTestLinq.id, objTestLinq.name, objTestLinq.value));
            name = "Test " + id.ToString();
            value = id++;
            objTestLinq = objLinqSample.Test2(name, value);
            Response.Write(string.Format("<h2>Test2: id:{0} - name:{1} - value:{2} </h2><br/>", objTestLinq.id, objTestLinq.name, objTestLinq.value));
            name = "Test " + id.ToString();
            value = id++;
            objTestLinq = objLinqSample.Test3(name, value);
            Response.Write(string.Format("<h2>Test3: id:{0} - name:{1} - value:{2} </h2><br/>", objTestLinq.id, objTestLinq.name, objTestLinq.value));
            name = "Test " + id.ToString();
            value = id++;
            objTestLinq = objLinqSample.Test4(name, value);
            Response.Write(string.Format("<h2>Test4: id:{0} - name:{1} - value:{2} </h2><br/>", objTestLinq.id, objTestLinq.name, objTestLinq.value));

            Response.Write("<h1>Linq Sample 2:</h1><br/>");
            LinqSample2 objLinqSample2 = new LinqSample2();
            name = "Test " + id.ToString();
            value = id++;
            objTestLinq = objLinqSample2.Test1(name, value);
            Response.Write(string.Format("<h2>Test1: id:{0} - name:{1} - value:{2} </h2><br/>", objTestLinq.id, objTestLinq.name, objTestLinq.value));
            name = "Test " + id.ToString();
            value = id++;
            objTestLinq = objLinqSample2.Test2(name, value);
            Response.Write(string.Format("<h2>Test2: id:{0} - name:{1} - value:{2} </h2><br/>", objTestLinq.id, objTestLinq.name, objTestLinq.value));
            name = "Test " + id.ToString();
            value = id++;
            objTestLinq = objLinqSample2.Test3(name, value);
            Response.Write(string.Format("<h2>Test3: id:{0} - name:{1} - value:{2} </h2><br/>", objTestLinq.id, objTestLinq.name, objTestLinq.value));
            name = "Test " + id.ToString();
            value = id++;
            objTestLinq = objLinqSample2.Test4(name, value);
            Response.Write(string.Format("<h2>Test4: id:{0} - name:{1} - value:{2} </h2><br/>", objTestLinq.id, objTestLinq.name, objTestLinq.value));
        }

        protected void btnLinqSample2_Click(object sender, EventArgs e)
        {
            LinqSample objLinqSample = new LinqSample();
            TestLinq objTestLinq = objLinqSample.Update(4, "Update", -1);
            Response.Write(string.Format("<h2>Update: id:{0} - name:{1} - value:{2} </h2><br/>", objTestLinq.id, objTestLinq.name, objTestLinq.value));
            
            WapDataClassesDataContext dc = new WapDataClassesDataContext();

            objTestLinq = dc.TestLinqs.Single(p => p.id == 4);
            objTestLinq.name = "Update";
            objTestLinq.value = -1;
            dc.SubmitChanges();
            Response.Write(string.Format("<h2>Update: id:{0} - name:{1} - value:{2} </h2><br/>", objTestLinq.id, objTestLinq.name, objTestLinq.value));
        }
    }
}
